package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SysSubstation;
import com.ruoyi.system.service.ISysSubstationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 厂站信息Controller
 * 
 * @author ruoyi
 * @date 2022-07-19
 */
@CrossOrigin
@Api("厂站信息管理")
@Controller
@RequestMapping("/system/substation")
public class SysSubstationController extends BaseController
{
    private String prefix = "system/substation";

    @Autowired
    private ISysSubstationService sysSubstationService;

//    @RequiresPermissions("system:substation:view")
    @GetMapping()
    public String substation()
    {
        return prefix + "/substation";
    }

    /**
     * 查询厂站信息列表
     */
    @ApiOperation("查询厂站信息列表")
//    @RequiresPermissions("system:substation:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysSubstation sysSubstation)
    {
        startPage();
        List<SysSubstation> list = sysSubstationService.selectSysSubstationList(sysSubstation);
        return getDataTable(list);
    }

    /**
     * 导出厂站信息列表
     */
    @ApiOperation("导出厂站信息列表")
//    @RequiresPermissions("system:substation:export")
    @Log(title = "厂站信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysSubstation sysSubstation)
    {
        List<SysSubstation> list = sysSubstationService.selectSysSubstationList(sysSubstation);
        ExcelUtil<SysSubstation> util = new ExcelUtil<SysSubstation>(SysSubstation.class);
        return util.exportExcel(list, "厂站信息数据");
    }

    /**
     * 新增厂站信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存厂站信息
     */
    @ApiOperation("新增保存厂站信息")
//    @RequiresPermissions("system:substation:add")
    @Log(title = "厂站信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysSubstation sysSubstation)
    {
        return toAjax(sysSubstationService.insertSysSubstation(sysSubstation));
    }

    /**
     * 修改厂站信息
     */
//    @RequiresPermissions("system:substation:edit")
    @GetMapping("/edit/{substationId}")
    public String edit(@PathVariable("substationId") Long substationId, ModelMap mmap)
    {
        SysSubstation sysSubstation = sysSubstationService.selectSysSubstationBySubstationId(substationId);
        mmap.put("sysSubstation", sysSubstation);
        return prefix + "/edit";
    }

    /**
     * 修改保存厂站信息
     */
    @ApiOperation("修改保存厂站信息")
//    @RequiresPermissions("system:substation:edit")
    @Log(title = "厂站信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysSubstation sysSubstation)
    {
        return toAjax(sysSubstationService.updateSysSubstation(sysSubstation));
    }

    /**
     * 删除厂站信息
     */
    @ApiOperation("删除厂站信息")
//    @RequiresPermissions("system:substation:remove")
    @Log(title = "厂站信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysSubstationService.deleteSysSubstationBySubstationIds(ids));
    }

    /**
     * 导入厂站信息
     */
    @ApiOperation("导入厂站信息")
//    @RequiresPermissions("system:substation:import")
    @Log(title = "厂站信息", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    @ResponseBody
    public AjaxResult importData(@RequestPart MultipartFile file, @RequestParam(defaultValue = "false") boolean updateSupport) throws Exception
    {
        ExcelUtil<SysSubstation> util = new ExcelUtil<SysSubstation>(SysSubstation.class);
        List<SysSubstation> list = util.importExcel(file.getInputStream());
        String message = sysSubstationService.importSubstation(list, updateSupport, getLoginName());
        return AjaxResult.success(message);
    }

    /**
     * 导出厂站信息模板
     */
    @ApiOperation("导出厂站信息模板")
//    @RequiresPermissions("system:substation:view")
    @Log(title = "厂站信息", businessType = BusinessType.EXPORT)
    @GetMapping("/importTemplate")
    @ResponseBody
    public AjaxResult importTemplate()
    {
        ExcelUtil<SysSubstation> util = new ExcelUtil<SysSubstation>(SysSubstation.class);
        return util.importTemplateExcel("厂站信息");
    }
}
